#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

struct stack
{
  int data;
  struct stack * next;
};

struct stack * top, * src, * bottom;

void empty()
{
  top = NULL;
}

struct stack * push(int value)
{
  src = (struct stack *) malloc(sizeof(struct stack));
  src->data = value;
  src->next = top; // 保存当前ktop地址
  if (top == NULL)
    bottom = src;
  top = src; // top指向新地址

  return top;
}

void pop()
{
  int y;

  if (top == NULL) {
    printf("stack is empty.\n");
    return ;
  }

  src = top;
  y = top->data;
  top = top->next;
  free(src);
  printf("pop value is %d\n", y);
}


int main()
{
  int b, n, i;
	
  empty();
  printf("How many times do you want to push and to pop\n");
  scanf("%d", &n);
	
  for (i = 1; i <= n; i++) {
    printf("Enter the %d times push value: ", i);
    scanf("%d", &b);
    push(b);
  }
  printf("\nThev value of bottom = %d\n", bottom->data);
	
  for (i = 1; i <= n; i++) {
    pop();
  }
	
  pop();
	
  return 0;
}

